package com.web.dao;

import com.web.entity.SupplyLighten;
import org.apache.ibatis.annotations.*;

public interface SupplyLightenMapper {
    @Delete({
        "delete from APP_SUPPLY_LIGHTEN",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    @Insert({
        "insert into APP_SUPPLY_LIGHTEN (user_id, supply_id, ",
        "times, create_time, ",
        "modify_time)",
        "values (#{userId,jdbcType=VARCHAR}, #{supplyId,jdbcType=INTEGER}, ",
        "#{times,jdbcType=TINYINT}, #{createTime,jdbcType=TIMESTAMP}, ",
        "#{modifyTime,jdbcType=TIMESTAMP})"
    })
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Integer.class)
    int insert(SupplyLighten record);

    int insertSelective(SupplyLighten record);

    @Select({
        "select",
        "id, user_id, supply_id, times, create_time, modify_time",
        "from APP_SUPPLY_LIGHTEN",
        "where id = #{id,jdbcType=INTEGER}"
    })
    @ResultMap("BaseResultMap")
    SupplyLighten selectByPrimaryKey(Integer id);

    int updateByPrimaryKeySelective(SupplyLighten record);

    @Update({
        "update APP_SUPPLY_LIGHTEN",
        "set user_id = #{userId,jdbcType=VARCHAR},",
          "supply_id = #{supplyId,jdbcType=INTEGER},",
          "times = #{times,jdbcType=TINYINT},",
          "create_time = #{createTime,jdbcType=TIMESTAMP},",
          "modify_time = #{modifyTime,jdbcType=TIMESTAMP}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(SupplyLighten record);

    /**
     * 查询用户是否已经为该供应点亮
     * @param supplyLighten
     * @return
     */
    SupplyLighten getSupplyLightenInfo(SupplyLighten supplyLighten);

    /**
     * 通过用户id和供应id查询供应点亮信息
     * @param userId
     * @param supplyId
     * @return
     */
    Integer countSupplyLighten(@Param("userId") String userId, @Param("supplyId") Integer supplyId);
}